package id;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;

import cn.rengy.tool.core._Snowflake;

/**
 * @author ：图灵-杨过
 * @date：2019/7/4
 * @version: V1.0
 * @slogan:天下风云出我辈，一入代码岁月催 description：
 */
public class CountDownLaunchRunner {

	private static _Snowflake snowflake=new _Snowflake(0,false);
     
	//static  Set<Long> synset = Collections.synchronizedSet(new HashSet<Long>(40000));
    public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
    	long now = System.currentTimeMillis();
        CountDownLatch countDownLatch = new CountDownLatch(1);
        /*new Thread(new SeeDoctorTask(countDownLatch)).start();
        new Thread(new QueueTask(countDownLatch)).start();*/


        for(int i=0;i<100;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    for(int j=0;j<100;j++){
                    	snowflake.nextId();
                    	//synset.add();
                    }
                    System.out.println("over，cost:"+(System.currentTimeMillis()-now));
                }
            }).start();
        }
        Thread.sleep(3000);
        //等待线程池中的2个任务执行完毕，否则一直等待,zk分布式锁
        countDownLatch.countDown();
        //set.add(2l);
        //System.out.println(synset.size());
    }

}
